package eu.jpereira.trainings.designpatterns.creational.builder.html;

import java.util.Iterator;

import eu.jpereira.trainings.designpatterns.creational.builder.ReportBodyBuilder;
import eu.jpereira.trainings.designpatterns.creational.builder.model.ReportBody;
import eu.jpereira.trainings.designpatterns.creational.builder.model.SoldItem;

public class HTMLReportBodyBuilder extends ReportBodyBuilder {
	
	private HTMLReportBody reportBody = new HTMLReportBody();

	@Override
	public ReportBody getReportBody() {
		
		// Add customer info
		reportBody.putContent("<span class=\"customerName\">");
		reportBody.putContent(customerName);
		reportBody.putContent("</span><span class=\"customerPhone\">");
		reportBody.putContent(phoneNumber);
		reportBody.putContent("</span>");
		
		// Add sales item info
		reportBody.putContent("<items>");
		Iterator<Item> it = soldItems.iterator();
		while ( it.hasNext() ) {
			Item item = it.next();
			reportBody.putContent("<item><name>");
			reportBody.putContent(item.name);
			reportBody.putContent("</name><quantity>");
			reportBody.putContent(item.quantity);
			reportBody.putContent("</quantity><price>");
			reportBody.putContent(item.price);
			reportBody.putContent("</price></item>");
		}
		reportBody.putContent("</items>");
		
		return reportBody;
	}

}
